################################################################################
# Judicial Ideology as Text -- Appendix Table 3 (Static Wordshoal Betas)
# Truscott & Romano
# Updated February 2025
################################################################################

################################################################################
# Necessary Packages & Dependencies
################################################################################

source('R/truscott_romano_source.R')

################################################################################
# Retrieve Betas
# Figure Retrieves from 'High' Estimates
################################################################################


beta_high <- data.frame(beta = wordshoals_static[['High']]$beta) %>%
  mutate(docket = levels(wordshoals_static[['High']]$groups))


important_cases <- which(abs(beta_high$beta) > quantile(abs(beta_high$beta), 0.95))


beta_high <- beta_high[important_cases,] %>%
  left_join(decisions %>% dplyr::select(term, docket, case_name), by  = 'docket') %>%
  unique() %>%
  mutate(beta = abs(beta),
         beta = round(beta, 3))



beta_static <- tibble(
  Term = c(beta_high$term),
  Docket = c(beta_high$docket),
  `Case Name` = c(beta_high$case_name),
  `Beta` = c(beta_high$beta)
)

table_A3_text <- stargazer(beta_static, type = 'text', summary = F, rownames = F)

table_A3_latex <- stargazer(beta_static, type = "latex", summary = FALSE, rownames = FALSE, label = 'tab:table_A3', title = 'Static Wordshoal Summary Outputs by High Beta Estimate', style = 'apsr') # As LaTex

writeLines(table_A3_text, 'tables/table_A3_text.txt', sep = '\n')
writeLines(table_A3_latex, 'tables/table_A3_latex.txt', sep = '\n')
